#include <Kharlia/Engine/Common.h>
#include <Kharlia/Engine/Init.h>
#include <Kharlia/Engine/Engine.h>

#include <CEGUIInputEvent.h>

namespace kharlia { namespace engine {

void _InitEngineBindings() {
    enum_<ui::MouseButton>("UIMouseButton")
        .value("BUTTON_LEFT", ui::LeftButton)
        .value("BUTTON_RIGHT", ui::RightButton)
        .value("BUTTON_MIDDLE", ui::MiddleButton)
        .export_values()
        ;

    enum_<ui::Key::Scan>("UIKey")
        .value("KEY_ARROW_LEFT", ui::Key::ArrowLeft)
        .value("KEY_ARROW_RIGHT", ui::Key::ArrowRight)
        .value("KEY_ARROW_UP", ui::Key::ArrowUp)
        .value("KEY_ARROW_DOWN", ui::Key::ArrowDown)
        .export_values()
        ;
        
    class_<CEngine, shared_ptr<CEngine>, bases<core::CSubsystem>, boost::noncopyable>
        ("CEngineBase", init<>())
        .def("Init", &CEngine::_Init)
        .def("Exit", &CEngine::_Exit)
        .def("InitClient", &CEngine::InitClient)
        .def("FiniClient", &CEngine::FiniClient)
        .def("Tick", &CEngine::Tick)
        .add_property("World", &CEngine::GetWorld, &CEngine::SetWorld)
        .add_property("Config", &CEngine::GetConfig, &CEngine::SetConfig)
        .def_readonly("LocalPlayer", &CEngine::mLocalPlayer)
        .add_property("ClientTickRate", &CEngine::GetClientTickRate, &CEngine::SetClientTickRate)
        .def_readonly("Client", &CEngine::mClient)
        .def("GetInstance", &CEngine::GetInstance).staticmethod("GetInstance")
        // EDITOR
        .add_property("EditorGridVisible", &CEngine::GetEditorGridVisible, &CEngine::SetEditorGridVisible)
        .add_property("EditorEnabled", &CEngine::GetEditorEnabled, &CEngine::SetEditorEnabled)
        .add_property("EditorBrush", make_getter(&CEngine::mEditorBrush), &CEngine::SetEditorBrush)
        .add_property("EditorBrushVisible", &CEngine::GetEditorBrushVisible, &CEngine::SetEditorBrushVisible)
        .add_property("EditorBrushPos", make_function(&CEngine::GetEditorBrushPos, return_internal_reference<>()), &CEngine::SetEditorBrushPos)
        .add_property("_EditorSelection", make_function(&CEngine::GetEditorSelection, return_internal_reference<>()), &CEngine::SetEditorSelection)
        .add_property("EditorSelectionVisible", &CEngine::GetEditorSelectionVisible, &CEngine::SetEditorSelectionVisible)
        ;

    KH_IMPL_GC(CEngine);
}

}}